import UploadFileVue from './main.vue'
import {createVNode, render} from 'vue';

// 参考mac/mode/index.js书写
// 参考：https://blog.csdn.net/weixin_43901089/article/details/121428038?spm=1001.2101.3001.6650.11&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-11-121428038-blog-129359029.235%5Ev38%5Epc_relevant_sort_base1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-11-121428038-blog-129359029.235%5Ev38%5Epc_relevant_sort_base1&utm_relevant_index=17
// https://www.jb51.net/article/281166.htm
const UploadFile = {
    install: (app, options) => {

        const node = document.createElement('div')
        let instance = createVNode(UploadFileVue, options)
        // instance.props.onDestroy = () => {
        //   render(null, parent)
        // }

        console.log("instance, ", instance)
        instance.appContext = app._context;


        // console.log("instance", UploadFileVue)
        // console.log("instance", instance)
        // console.log("instance", app)

        render(instance, node)

        document.body.appendChild(node)
        console.log("UploadFile",app.config.globalProperties)
        app.config.globalProperties.$wkUploadFile = instance
        app.config.globalProperties.$wkUploadFile.upload = instance.component.exposed.upload

        console.log("UploadFile",app.config.globalProperties)
    }
}
export default UploadFile

// 下面是原来的代码
// const UploadFile = {}
//
// UploadFile.install = (Vue) => {
//   const UploadFileConstructor = Vue.extend(UploadFileVue)
//   const instance = new UploadFileConstructor({
//     el: document.createElement('div')
//   })
//   document.body.appendChild(instance.$el)
//
//
//   Vue.prototype.$wkUploadFile = instance
// }
//
// export default UploadFile
